package com.GGG.cloud.house.agent.web;

import com.GGG.cloud.house.agent.domain.entity.Agency;
import com.GGG.cloud.house.agent.domain.entity.Agent;
import com.GGG.cloud.house.agent.domain.entity.User;
import com.GGG.cloud.house.agent.domain.vo.AgencyInfo;
import com.GGG.cloud.house.agent.domain.vo.AgentInfo;
import com.GGG.cloud.house.agent.domain.vo.PropertiesVo;
import com.GGG.cloud.house.agent.service.AgencyService;
import com.GGG.cloud.house.agent.service.AgentService;
import com.GGG.cloud.house.agent.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @ClassName AgentController
 * @Author Wing
 * @Date 2020/9/29 15:07
 * @Version 1.0
 * @Remarks TODO
 */
@Controller
public class AgentController {

    @Autowired
    private UserService userService;

    @Autowired
    private AgentService agentService;

    @Autowired
    private AgencyService agencyService;

    @RequestMapping("agent-details.html")
    public String agentDetails(ModelMap modelMap){
        modelMap.put("desc","");
        modelMap.put("title","房产交易平台");

        // set agent info
        Agent agent = agentService.get(1L);
        User user = userService.get(agent.getUserId());
        Agency agency = agencyService.get(agent.getAgencyId());
        System.out.println(agency);
        AgentInfo agentInfo = new AgentInfo();
        agentInfo.setUser(user);
        agentInfo.setAgent(agent);
        agentInfo.setAgency(agency);

        // agentInfo.setImg("assets/images/agent/agent-1.jpg");
        // agentInfo.setName("Donald Palmer");
        // agentInfo.setBrief("Donald Palmer is a Specialist Real Estate Agent with 8 years of   Experience in Real Estate field. He achive success with his honesty,determination, hardwork and c`ommetment. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et, totam?");
        // agentInfo.setAddress("256, 1st AVE, Manchester 125 , Noth England");
        // agentInfo.setPhone("(756) 447 5779");
        // agentInfo.setMail("info@example.com");
        // agentInfo.setGlobal("www.example.com");
        // agentInfo.setPhoto("5 Properties");
        modelMap.put("agentInfo",agentInfo);

        // set house Properties list
        List<PropertiesVo> properties = new ArrayList<>();
        properties.add(new PropertiesVo("500 平米",6,4,3,"锦江区东大街下东大街568号","江南宅院",550,"出租","assets/images/property/property-1.jpg"));
        properties.add(new PropertiesVo("500 平米",6,4,3,"城北大道450附22号","木马山别墅",2550,"出售","assets/images/property/property-2.jpg"));
        properties.add(new PropertiesVo("500 平米",6,4,3,"锦江区福字街215号","皇家一号公寓",550,"出租","assets/images/property/property-3.jpg"));
        properties.add(new PropertiesVo("500 平米",6,4,3,"龙泉驿区南山大道333号附12号","龙城一号别墅",550,"出租","assets/images/property/property-4.jpg"));
        properties.add(new PropertiesVo("500 平米",6,4,3,"金牛区琴台西路668号","春天花园别墅",2550,"出售","assets/images/property/property-5.jpg"));
        modelMap.put("properTiesVO",properties);
        return "agent-details";
    }

    @RequestMapping("agents.html")
    public String agents(ModelMap modelMap){
        modelMap.put("desc","");
        modelMap.put("title","房产交易平台");

        List<Agent> agents = agentService.listAll();
        List<AgentInfo> agentInfos = new ArrayList<>();

        List<Long> ids = new ArrayList<>();

        for (Agent agent : agents) {
            ids.add(agent.getUserId());
            AgentInfo agentInfo = new AgentInfo();
            agentInfo.setAgent(agent);
            agentInfos.add(agentInfo);
        }

        List<User> users = userService.selectUserInId(ids);
        for (int i = 0; i < agentInfos.size(); i++) {
            agentInfos.get(i).setUser(users.get(i));
        }

        modelMap.put("agentInfos",agentInfos);
        return "agents";
    }

    @RequestMapping("agents-3-column.html")
    public String agents3(ModelMap modelMap){
        modelMap.put("desc","");
        modelMap.put("title","房产交易平台");
        List<Agent> agents = agentService.listAll();
        List<AgentInfo> agentInfos = new ArrayList<>();

        List<Long> ids = new ArrayList<>();

        for (Agent agent : agents) {
            ids.add(agent.getUserId());
            AgentInfo agentInfo = new AgentInfo();
            agentInfo.setAgent(agent);
            agentInfos.add(agentInfo);
        }

        List<User> users = userService.selectUserInId(ids);
        for (int i = 0; i < agentInfos.size(); i++) {
            agentInfos.get(i).setUser(users.get(i));
        }
        modelMap.put("agentInfos",agentInfos);
        return "agents-3-column";
    }

    @RequestMapping("agents-carousel-3-column.html")
    public String carousel3Column(ModelMap modelMap){
        modelMap.put("desc","");
        modelMap.put("title","房产交易平台");
        List<Agent> agents = agentService.listAll();
        List<AgentInfo> agentInfos = new ArrayList<>();

        List<Long> ids = new ArrayList<>();

        for (Agent agent : agents) {
            ids.add(agent.getUserId());
            AgentInfo agentInfo = new AgentInfo();
            agentInfo.setAgent(agent);
            agentInfos.add(agentInfo);
        }

        List<User> users = userService.selectUserInId(ids);
        for (int i = 0; i < agentInfos.size(); i++) {
            agentInfos.get(i).setUser(users.get(i));
        }
        modelMap.put("agentInfos",agentInfos);
        return "agents-carousel-3-column";
    }

    @RequestMapping("agents-carousel2-3-column.html")
    public String carousel23Column(ModelMap modelMap){
        modelMap.put("desc","");
        modelMap.put("title","房产交易平台");
        List<Agent> agents = agentService.listAll();
        List<AgentInfo> agentInfos = new ArrayList<>();

        List<Long> ids = new ArrayList<>();

        for (Agent agent : agents) {
            ids.add(agent.getUserId());
            AgentInfo agentInfo = new AgentInfo();
            agentInfo.setAgent(agent);
            agentInfos.add(agentInfo);
        }

        List<User> users = userService.selectUserInId(ids);
        for (int i = 0; i < agentInfos.size(); i++) {
            agentInfos.get(i).setUser(users.get(i));
        }
        modelMap.put("agentInfos",agentInfos);
        return "agents-carousel2-3-column";
    }

    @RequestMapping("agents-carousel-4-column.html")
    public String carousel4Column(ModelMap modelMap){
        modelMap.put("desc","");
        modelMap.put("title","房产交易平台");
        List<Agent> agents = agentService.listAll();
        List<AgentInfo> agentInfos = new ArrayList<>();

        List<Long> ids = new ArrayList<>();

        for (Agent agent : agents) {
            ids.add(agent.getUserId());
            AgentInfo agentInfo = new AgentInfo();
            agentInfo.setAgent(agent);
            agentInfos.add(agentInfo);
        }

        List<User> users = userService.selectUserInId(ids);
        for (int i = 0; i < agentInfos.size(); i++) {
            agentInfos.get(i).setUser(users.get(i));
        }
        modelMap.put("agentInfos",agentInfos);
        return "agents-carousel-4-column";
    }

    @RequestMapping("agents-carousel2-4-column.html")
    public String carousel24Column(ModelMap modelMap){
        modelMap.put("desc","");
        modelMap.put("title","房产交易平台");
        List<Agent> agents = agentService.listAll();
        List<AgentInfo> agentInfos = new ArrayList<>();

        List<Long> ids = new ArrayList<>();

        for (Agent agent : agents) {
            ids.add(agent.getUserId());
            AgentInfo agentInfo = new AgentInfo();
            agentInfo.setAgent(agent);
            agentInfos.add(agentInfo);
        }

        List<User> users = userService.selectUserInId(ids);
        for (int i = 0; i < agentInfos.size(); i++) {
            agentInfos.get(i).setUser(users.get(i));
        }
        modelMap.put("agentInfos",agentInfos);
        return "agents-carousel2-4-column";
    }
}
